package com.hmall.order.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
public class FeignClientMY implements RequestInterceptor {
    static String a = null;

    @Override
    public void apply(RequestTemplate template) {

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String id = null;
        if (requestAttributes != null) {

            HttpServletRequest request = requestAttributes.getRequest();
            id = request.getHeader("authorization");
        }else {
            id = TreadLocalMain.getname();
        }

        log.info("sss");


        log.info("===request: {}", template.url());
        template.header("authorization", id);
    }
}